package com.wlz.basic.serializable;

import lombok.Data;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;

/**
 * @author： wlz
 * @Date 2020/6/9 10:31
 * @description： TODO
 * @version: 1.0
 */
@Data
public class Student implements Serializable {

    private static final long serialVersionUID = -363977138234864442L;



    private String name;
    private Integer age;
    private Integer score;

    private transient String password;

    public Student() {

    }

    public Student(Integer integer) {
    }

    private void readObject( ObjectInputStream objectInputStream ) throws IOException, ClassNotFoundException {

        // 调用默认的反序列化函数
        objectInputStream.defaultReadObject();

        // 手工检查反序列化后学生成绩的有效性，若发现有问题，即终止操作！
        if( 0 > score || 100 < score ) {
            throw new IllegalArgumentException("学生分数只能在0到100之间！");
        }
    }

}
